class Solution
{
public:
    int minimumDeletions(string word, int k)
    {
        vector<int> freq(26, 0);
        for (auto c : word)
        {
            freq[c - 'a']++;
        }

        int result = INT_MAX;
        for (auto startFreq : freq)
        {
            int endFreq = startFreq + k;
            int change = 0;
            for (auto f : freq)
            {
                if (f < startFreq)
                {
                    change += f;
                }
                else if (f > endFreq)
                {
                    change += f - endFreq;
                }
            }
            result = min(result, change);
        }
        return result;
    }
};